/***********************************************************************
 * Module:  Subject.java
 * Author:  DAC
 * Purpose: Defines the Class Subject
 ***********************************************************************/
package com.group1.model;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.hibernate.Query;
import org.hibernate.Session;

/** @pdOid 369c741b-8eb2-40a2-bf6d-b415ffd68712 */
public class Subject {
   /** @pdOid cbf4a695-e0b7-45db-a6f3-18b4cd5c9b4a */
   protected void finalize() {
      // TODO: implement
   }
   
   /** @pdOid 64e8cbf7-0f8c-404b-ad11-6db00d850261 */
   public java.lang.String subjectId;
   /** @pdOid cf12e640-ded4-41a8-93b5-b55be4de5da6 */
   public java.lang.String subjectName;
   /** @pdOid 46a340b5-bd37-4484-bf85-b723af983374 */
   public java.lang.String subjectShortname;
   /** @pdOid 145c723f-ab9d-4889-88a7-ea347369ec49 */
   public int subjectCredits;
   
   /** @pdRoleInfo migr=no name=Topic assc=topicOfSubject coll=java.util.Collection impl=java.util.HashSet mult=0..* */
   private Set SubjectTopicMapping = new HashSet(0);
   /** @pdRoleInfo migr=no name=Lecturer assc=subjectOfLecturer coll=java.util.Collection impl=java.util.HashSet mult=0..* side=A */
//   public java.util.Collection<Lecturer> lecturerSubjectMapping;
   private Set lecturerSubjectMapping = new HashSet(0);
   
   public static List<Subject> getAllSubject(Session session)
   {
	   Query query = session.createQuery("from Subject");                
	   List <Subject> listOfSubject = query.list();
	   return listOfSubject;
   }
   
   public static Subject getSubjectById(String subjectID, Session session)
   {
	   return (Subject) session.load(Subject.class, subjectID);
   }
   
   public static Set  getSubjectByLecturer(String lecturerID, Session session)
   {
	  Lecturer l = Lecturer.getLecturerByID(session, lecturerID);
	  return  l.getLecturerSubjectMapping();
   }
   
   
   /** @pdOid eb4b39ee-1b71-483a-b247-a26833722ef8 */
   public java.lang.String getSubjectId() {
      return subjectId;
   }
   
   /** @param newSubjectId
    * @pdOid 6be4daa2-9011-4463-b7ac-ae0807a3fd64 */
   public void setSubjectId(java.lang.String newSubjectId) {
      subjectId = newSubjectId;
   }
   
   /** @pdOid 82cccea5-b23c-4e34-92b8-1dc4ebd8f753 */
   public Subject() {
      // TODO: implement
   }
   
   /** @pdOid e724db9d-307c-470d-bd4b-5fb9bd7bf986 */
   public java.lang.String getSubjectName() {
      return subjectName;
   }
   
   /** @param newSubjectName
    * @pdOid d02224b5-ef1f-4e74-9910-580a1b9dee82 */
   public void setSubjectName(java.lang.String newSubjectName) {
      subjectName = newSubjectName;
   }
   
   /** @pdOid 779bf954-e14d-405d-908a-6a859f1455e9 */
   public java.lang.String getSubjectShortname() {
      return subjectShortname;
   }
   
   /** @param newSubjectShortname
    * @pdOid cbe4371e-9e7c-4a56-bd79-3f4f40f6c098 */
   public void setSubjectShortname(java.lang.String newSubjectShortname) {
      subjectShortname = newSubjectShortname;
   }
   
   /** @pdOid 6b6174a4-fb69-4e27-9360-73ae2b7846e7 */
   public int getSubjectCredits() {
      return subjectCredits;
   }
   
   /** @param newSubjectCredits
    * @pdOid e381b97c-b2f5-4762-b9da-57f37ee7b15a */
   public void setSubjectCredits(int newSubjectCredits) {
      subjectCredits = newSubjectCredits;
   }
   
   
//   /** @pdGenerated default getter */
//   public java.util.Collection<Topic> getSubjectTopicMapping() {
//      if (SubjectTopicMapping == null)
//         SubjectTopicMapping = new java.util.HashSet<Topic>();
//      return SubjectTopicMapping;
//   }
   
   /** @pdGenerated default iterator getter */
   public java.util.Iterator getIteratorSubjectTopicMapping() {
      if (SubjectTopicMapping == null)
         SubjectTopicMapping = new java.util.HashSet<Topic>();
      return SubjectTopicMapping.iterator();
   }
   
//   /** @pdGenerated default setter
//     * @param newSubjectTopicMapping */
//   public void setSubjectTopicMapping(java.util.Collection<Topic> newSubjectTopicMapping) {
//      removeAllSubjectTopicMapping();
//      for (java.util.Iterator iter = newSubjectTopicMapping.iterator(); iter.hasNext();)
//         addSubjectTopicMapping((Topic)iter.next());
//   }
   
   public Set getSubjectTopicMapping() {
		return this.SubjectTopicMapping;
	}

	public void setSubjectTopicMapping(Set SubjectTopicMapping) {
		this.SubjectTopicMapping = SubjectTopicMapping;
	}
   
   /** @pdGenerated default add
     * @param newTopic */
   public void addSubjectTopicMapping(Topic newTopic) {
      if (newTopic == null)
         return;
      if (this.SubjectTopicMapping == null)
         this.SubjectTopicMapping = new java.util.HashSet<Topic>();
      if (!this.SubjectTopicMapping.contains(newTopic))
      {
         this.SubjectTopicMapping.add(newTopic);
         newTopic.addSubjectTopicMapping(this);      
      }
   }
   
   /** @pdGenerated default remove
     * @param oldTopic */
   public void removeSubjectTopicMapping(Topic oldTopic) {
      if (oldTopic == null)
         return;
      if (this.SubjectTopicMapping != null)
         if (this.SubjectTopicMapping.contains(oldTopic))
         {
            this.SubjectTopicMapping.remove(oldTopic);
            oldTopic.removeSubjectTopicMapping(this);
         }
   }
   
   /** @pdGenerated default removeAll */
   public void removeAllSubjectTopicMapping() {
      if (SubjectTopicMapping != null)
      {
         Topic oldTopic;
         for (java.util.Iterator iter = getIteratorSubjectTopicMapping(); iter.hasNext();)
         {
            oldTopic = (Topic)iter.next();
            iter.remove();
            oldTopic.removeSubjectTopicMapping(this);
         }
      }
   }
//   /** @pdGenerated default getter */
//   public java.util.Collection<Lecturer> getLecturerSubjectMapping() {
//      return lecturerSubjectMapping;
//   }
   public Set getLecturerSubjectMapping() {
		return this.lecturerSubjectMapping;
	}

   public void setLecturerSubjectMapping(Set lecturerSubjectMapping) {
		this.lecturerSubjectMapping = lecturerSubjectMapping;
	}
   
   
   /** @pdGenerated default iterator getter */
   public java.util.Iterator getIteratorLecturerSubjectMapping() {
      if (lecturerSubjectMapping == null)
         lecturerSubjectMapping = new java.util.HashSet<Lecturer>();
      return lecturerSubjectMapping.iterator();
   }
   
//   /** @pdGenerated default setter
//     * @param newLecturerSubjectMapping */
//   public void setLecturerSubjectMapping(java.util.Collection<Lecturer> newLecturerSubjectMapping) {
//      removeAllLecturerSubjectMapping();
//      for (java.util.Iterator iter = newLecturerSubjectMapping.iterator(); iter.hasNext();)
//         addLecturerSubjectMapping((Lecturer)iter.next());
//   }
   
   /** @pdGenerated default add
     * @param newLecturer */
   public void addLecturerSubjectMapping(Lecturer newLecturer) {
      if (newLecturer == null)
         return;
      if (this.lecturerSubjectMapping == null)
         this.lecturerSubjectMapping = new java.util.HashSet<Lecturer>();
      if (!this.lecturerSubjectMapping.contains(newLecturer))
      {
         this.lecturerSubjectMapping.add(newLecturer);
         newLecturer.addLecturerSubjectMapping(this);      
      }
   }
   
   /** @pdGenerated default remove
     * @param oldLecturer */
   public void removeLecturerSubjectMapping(Lecturer oldLecturer) {
      if (oldLecturer == null)
         return;
      if (this.lecturerSubjectMapping != null)
         if (this.lecturerSubjectMapping.contains(oldLecturer))
         {
            this.lecturerSubjectMapping.remove(oldLecturer);
            oldLecturer.removeLecturerSubjectMapping(this);
         }
   }
   
   /** @pdGenerated default removeAll */
   public void removeAllLecturerSubjectMapping() {
      if (lecturerSubjectMapping != null)
      {
         Lecturer oldLecturer;
         for (java.util.Iterator iter = getIteratorLecturerSubjectMapping(); iter.hasNext();)
         {
            oldLecturer = (Lecturer)iter.next();
            iter.remove();
            oldLecturer.removeLecturerSubjectMapping(this);
         }
      }
   }

}